<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="vue/vue.min.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="app">

        <label>id:
            <input type="text" v-model="id">
        </label>

        <label>name:
            <input type="text" v-model="name">
        </label>

        <input type="button" value="添加" v-on:click="add">
        <!-- key属性只能是number或string类型,不能是对象 -->
        <p v-for="item in list" v-bind:key="item.id">
            <input type="checkbox">{{item.id}}----{{item.name}}
        </p>

    </div>
    <script>
        var vm = new Vue({
            el:'#app',//选择器
            data:{
                id: '',
                name: '',
                list: [
                    {id:1,name:'张三'},
                    {id:2,name:'李四'},
                    {id:3,name:'王二'},
                    {id:4,name:'麻子'}
                ]
            },
            methods:{
                //函数
                add(){
                    // this.list.push({id: this.id,name: this.name})
                    this.list.unshift({id: this.id,name: this.name})
                }
            }
        })
    </script>
</body>
</html>